﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using BLL;
using DAL;
using Models;
using System.Data;
using System.Text;
using System.Xml;
using Gift.WebApp;
using AjaxPro;


public partial class backstage_goods_batch_add : System.Web.UI.Page
{
    // Fields
    protected AttributesManager am = new AttributesManager();

    protected CategoryManager cm = new CategoryManager();

    protected FreightTemplateManager ftm = new FreightTemplateManager();
    protected GoodsAttributeManager gam = new GoodsAttributeManager();
    protected GoodsCategory gc = new GoodsCategory();
    protected GoodsCategoryManager gcm = new GoodsCategoryManager();
    protected GoodsEntitysManager gem = new GoodsEntitysManager();
    protected GoodsEntitysSpecificationsManager gesm = new GoodsEntitysSpecificationsManager();
    protected GoodGalleryManager ggm = new GoodGalleryManager();
    protected GoodsManager gm = new GoodsManager();
    protected Goods gs = new Goods();
    protected GoodsTypeManager gtm = new GoodsTypeManager();

    protected SpecificationsManager sm = new SpecificationsManager();


    // Methods
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
    }

    protected StringBuilder CategoryBind()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            this.RecursionCategory(sb, "00000000-0000-0000-0000-000000000000", this.Session["language_version"].ToString());
        }
        catch
        {
        }
        return sb;
    }

    protected StringBuilder FreightTemplateBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            DataTable freightTemplateByLanguageVersion = this.ftm.GetFreightTemplateByLanguageVersion(this.Session["language_version"].ToString());
            foreach (DataRow row in freightTemplateByLanguageVersion.Rows)
            {
                builder.AppendLine(string.Concat(new object[] { "<option value=\"", row["id"], "\">", row["freightTemplateName"], "</option>" }));
            }
        }
        catch
        {
        }
        return builder;
    }

    protected StringBuilder GoodsTypeBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            DataTable goodsTypeByLanguageVersion = this.gtm.GetGoodsTypeByLanguageVersion(this.Session["language_version"].ToString());
            foreach (DataRow row in goodsTypeByLanguageVersion.Rows)
            {
                builder.AppendLine("<option value=\"" + row["id"].ToString() + "\">" + row["typeName"].ToString() + "</option>");
            }
        }
        catch
        {
        }
        return builder;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if ((HttpContext.Current.Session["admin_user"] == null) && (HttpContext.Current.Session["language_version"] == null))
        {
            base.ClientScript.RegisterStartupScript(base.GetType(), "sJs", "top.location=\"login.html\";", true);
        }
        Utility.RegisterTypeForAjax(typeof(Goods_ajax));
        if (!base.IsPostBack)
        {
            this.rdIsBest0.Checked = true;
            this.rdIsNew0.Checked = true;
            this.rdIsTopSelling0.Checked = true;
            this.rdIsShelves1.Checked = true;
            this.rdIsPromote0.Checked = true;
            this.rdIsUserDiscount1.Checked = true;
            this.cbIsOrderFromFreight.Checked = true;
            this.cbIsDiscount.Checked = true;
            this.cbIsTotalReduce.Checked = true;
            this.cbIsGifts.Checked = true;
            this.cbIsSendIntegral.Checked = true;
            this.rdIsFromFreight0.Checked = true;
            this.hdLanguageVersion.Value = HttpContext.Current.Session["language_version"].ToString();
        }
    }

    private void RecursionCategory(StringBuilder sb, string parentCategory, string languageVersion)
    {
        DataTable table = this.cm.GetCategoryByParentIdAndLanguageVersionAndIsShow(parentCategory, languageVersion, -1);
        if (table.Rows.Count > 0)
        {
            foreach (DataRow row in table.Rows)
            {
                string str = "";
                int num = Convert.ToInt32(row["depth"]);
                if (num > 0)
                {
                    for (int i = 0; i < num; i++)
                    {
                        str = str + "&nbsp;&nbsp;&nbsp;&nbsp;";
                    }
                    str = str + "┣";
                }
                sb.AppendLine("<option value=\"" + row["categoryIdentity"].ToString() + "\">" + str + row["categoryName"].ToString() + "</option>");
                this.RecursionCategory(sb, row["id"].ToString(), languageVersion);
            }
        }
    }

    protected StringBuilder SpecificationsBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            DataTable specificationsByLanguageVersion = this.sm.GetSpecificationsByLanguageVersion(this.Session["language_version"].ToString());
            bool flag = false;
            foreach (DataRow row in specificationsByLanguageVersion.Rows)
            {
                builder.AppendLine("" + (!flag ? "" : "<br/>") + "<input id=\"cb" + row["id"].ToString() + "\" value=\"" + row["id"].ToString() + "\" name=\"ss\" type=\"checkbox\" onclick=\"getSpecificationsBatch(" + row["id"].ToString() + ",this);\" />[" + row["specificationsName"].ToString() + "]");
                flag = true;
            }
        }
        catch
        {
        }
        return builder;
    }

}